package tree_util;

import com.opensymphony.xwork2.ActionSupport;
import db_tool.DBConnection;
import org.apache.struts2.ServletActionContext;

import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 添加、更新、删除	鱼样本
 * */
public class CountInfo extends ActionSupport {

	private PrintWriter writer = null;
	
	private DBConnection db_connection = null;
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
		writer = ServletActionContext.getResponse().getWriter();
		db_connection = DBConnection.getInstance();
		Statement statement = null;
		String result = "";
		ResultSet rs[]={null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
		statement = db_connection.getStatement();
		String[] sql={null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
		sql[0] = "SELECT * FROM MonitoringSite";
		sql[1] = "SELECT * FROM FractureSurface";
		sql[2] = "SELECT * FROM MeasuringLine";
		sql[3] = "SELECT * FROM MeasuringPoint";
		sql[4] = "SELECT * FROM WaterLayer";
		sql[5] = "SELECT * FROM CatchTools";
		sql[6] = "SELECT * FROM Catches";
		sql[7] = "SELECT * FROM Fishes";
		sql[8] = "SELECT * FROM FishEggs";
		sql[9] = "SELECT * FROM Sediment";
		sql[10] = "SELECT * FROM Zooplankton";
		sql[11] = "SELECT * FROM DominantZooplanktonSpecies";
		sql[12] = "SELECT * FROM Phytoplankton";
		sql[13] = "SELECT * FROM DominantPhytoplanktonSpecies";
		sql[14] = "SELECT * FROM Benthos";
		sql[15] = "SELECT * FROM DominantBenthosSpecies";
		int[] count = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
		try {
			
			for(int i=0;i<16;i++) {
				rs[i] = statement.executeQuery(sql[i]);
				while(rs[i].next()){
					count[i]++;
				}
				result += count[i]+",";
				System.out.print(count[i]+"---");
			}
			
			writer.write(result);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			writer.write("error");
			System.out.println("--查询错误--");
			e.printStackTrace();
		}finally{
			try {
				db_connection.close(statement);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println("关闭失败");
				e.printStackTrace();
			}
		}
		return null;
	}

}
